//
//  File.swift
//  SyncKit
//
//  Created by tangjilin on 2025/7/15.
//

import Foundation

struct Recording: Identifiable {
    let id: UUID
    let date: Date        // 存储完整日期
    let duration: Double  // 存储时长（秒）
    
    // 计算属性：格式化的日期字符串
    var dateStr: String {
        let formatter = DateFormatter()
        formatter.dateFormat = "MM:dd"  // 格式化为 "07:12"
        return formatter.string(from: date)
    }
    
    // 计算属性：格式化的时间字符串
    var timeStr: String {
        let formatter = DateFormatter()
        formatter.dateFormat = "HH:mm"  // 格式化为 "12:23"
        return formatter.string(from: date)
    }
    
    // 计算属性：格式化的时长字符串
    var durationStr: String {
        let minutes = Int(duration) / 60
        let seconds = Int(duration) % 60
        return String(format: "%02d:%02d", minutes, seconds)
    }
    
    let fileURL: String?
    
    // 初始化方法
    init(
        id: UUID = UUID(),
        date: Date = Date(),
        duration: Double,
        fileURL: String?
    ) {
        self.id = id
        self.date = date
        self.duration = duration
        self.fileURL = fileURL
    }
}
